<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('商品移库')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-edit" th:object="${shopGoods}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label">商品类别：</label>
                <div class="col-sm-8">
                        <input id="treeId" name="goodsTypeId" type="hidden" th:field="*{goodsTypeId}">
                        <input class="form-control" type="text" id="treeName" th:value="${shopGoodsType.goodsTypeName}" readonly="true" required>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label">商品编码：</label>
                <div class="col-sm-8">
                    <input name="goodsCode" th:field="*{goodsCode}" class="form-control" type="text" maxlength="16" required readonly>
                </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label">商品名称：</label>
                <div class="col-sm-8">
                    <input name="goodsName" th:field="*{goodsName}" class="form-control" type="text" maxlength="30" required readonly>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label">商品条码：</label>
                <div class="col-sm-8">
                    <input name="goodsBarcode" th:field="*{goodsBarcode}" class="form-control" type="text" maxlength="30" readonly>
                </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label">所属库位：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="storageId" name="storageId" type="hidden" th:field="*{storageId}">
                        <input class="form-control" type="text" onclick="selectStorage()" id="storageName" name="storageName" th:value="${whStorage.storageName}" readonly="true" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
        </div>


    </form>
</div>


<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "shop/goods"
    $("#form-goods-add").validate({
        onkeyup: false,
        rules:{
            reservoirCode:{
                minlength: 2,
                maxlength: 16,
                remote: {
                    url: prefix + "/checkGoodsCodeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "goodsCode": function() {
                            return $.common.trim($("#goodsCode").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            costPrice:{ number:true,min:0 },
            retailPrice:{ number:true,min:0 },
            sellingPrice:{ number:true,min:0 },
            wholesalePrice:{ number:true,min:0 },
            safetyStock:{ digits:true, },
        },
        messages: {
            "goodsCode": {
                remote: "商品编码已存在"
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/editSaveTransfer", $('#form-goods-edit').serialize());
        }
    }

    /* 选择库位 */
    var storagePrefix = ctx + "wh/storage"
    function selectStorage() {
        var url = storagePrefix + '/selectStorage';
        var options = {
            title: '选择库位(储位)',
            url: url,
            callBack: doSubmitStorage
        };
        $.modal.openOptions(options);
    }

    function doSubmitStorage(index, layero){
        var iframeWin = layero.find("iframe")[0].contentWindow.$.table;
        var rows = iframeWin.selectFirstColumns();//调用子页面的方法 获取ID
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }

        $('#storageId').val(rows.join())
        var storageName=iframeWin.selectColumns("storageName");//调用子页面的方法 获取ID
        $('#storageName').val(storageName)
        layer.close(index);
    }
</script>
</body>
</html>